package yawning.mew.cat;

import yawning.mew.sim.SimulationAction;
import yawning.mew.sim.SimulationEventAction;

public class EventBerserk extends SimulationEventAction {
	CatModelSimState mState;
	double mCooldownExpireTime;

	EventBerserk(CatModelSimState state) {
		super(state.mSimEngine);
		mState = state;
		if (mState.mModel.druid.getTalent(CatModel.BERSERK) == 0) mCooldownExpireTime = Double.MAX_VALUE;
	}

	@Override
	public double perform() {
		if (isUp() || mCooldownExpireTime > mState.mSimEngine.getSimTime()) return SimulationAction.ACTION_FAIL;
		if (mState.mIsLogging) mState.mLog.log("Berserk\n");

		mNrBerserk++;

		schedule(mState.mModel.berserkBuffDuration);
		mCooldownExpireTime = mState.mSimEngine.getSimTime() + mState.mModel.berserkCDDuration;
		mState.onPrimalMadnessGain();
		return 0.0f;
	}

	@Override
	public void onExpire() {
		if (mState.mIsLogging) mState.mLog.log("Berserk: Expiration\n");
		mState.onPrimalMadnessLoss(false);
	}

	public void onTier12_4pc_tigger(int nrCps) {
		// Model what possibly is the worst set bonus ever.
		if (mState.mModel.druid.tier_12_4pc && isUp()) {
			if (nrCps == 5 || mState.mSimEngine.getRandom().nextBoolean(nrCps * mState.mModel.tier_12_4pc_procRate)) {
				if (mState.mIsLogging) mState.mLog.log("Tier 12 4pc: Berserk Extention Remaining: %.3f + 2.0\n", mState.getBerserkRemaining());

				extendExpiry(mState.mModel.tier_12_4pc_extDuration);

				// It may be something more like this, but probably not?
				// extendExpiry(2 + nrCps * mState.mModel.tier_12_4pc_extDuration);
			}
		}
	}

	int mNrBerserk = 0;
}